package com.lepu.app.fun.my;

import java.io.File;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.app.application.MyApplication;
import com.app.utils.LoginUtil;
import com.app.utils.ObserverConst;
import com.app.utils.SdLocal;
import com.app.utils.Setting;
import com.core.lib.application.BaseFragmentActivity;
import com.core.lib.core.ApiClient;
import com.core.lib.core.AsyncRequest;
import com.core.lib.core.BitmapManager;
import com.core.lib.ui.wheel.OnWheelChangedListener;
import com.core.lib.ui.wheel.WheelView;
import com.core.lib.utils.CallBack;
import com.core.lib.utils.DateType;
import com.core.lib.utils.EmojiFilter;
import com.core.lib.utils.ObserverManager;
import com.core.lib.utils.PopUtil;
import com.core.lib.utils.geneal.UploadMenuImage;
import com.core.lib.utils.main.DateUtilBase;
import com.core.lib.utils.main.ImageUtilBase;
import com.core.lib.utils.main.SdUtilBase;
import com.core.lib.utils.main.UIHelper;
import com.core.lib.utils.main.UtilityBase;
import com.core.lib.widget.MyDialog;
import com.lepu.app.fun.my.bean.BeanMyUserInfoHospital;
import com.lepu.app.fun.my.bean.BeanMyUserInfoKeShi;
import com.lepu.app.main.adapter.CityWheelAdapter;
import com.lepu.app.main.adapter.DistrictWheelAdapter;
import com.lepu.app.main.adapter.ProvinceWheelAdapter;
import com.lepu.app.main.bean.BeanArea;
import com.lepu.app.main.permission.PermissionUtil;
import com.lepu.app.main.permission.callback.PermissionResultCallBack;
import com.lepu.app.usercenter.bean.LoginInfo;
import com.lepu.app.usercenter.bean.LoginInfoIllnessTags;
import com.lepu.app.widget.CustomTopBarNew;
import com.lepu.app.widget.CustomTopBarNew.OnTopbarNewLeftLayoutListener;
import com.lepu.app.widget.CustomTopBarNew.OnTopbarNewRightButtonListener;
import com.lepu.pasm.R;

/**
 * 个人资料
 * 
 * @author wxd
 * 
 */
public class MyUserInfoActivity extends BaseFragmentActivity implements
		OnTopbarNewLeftLayoutListener, OnTopbarNewRightButtonListener,
		AsyncRequest {

	private static final int INPUT_NAME = 10;// 姓名
	private static final int INPUT_CUSTOM_FEEL = 11;// 个性签名
	private static final int INPUT_HEIGHT = 12;// 身高
	private static final int INPUT_MOBILE_PHONE = 13;// 联系电话
	private static final int INPUT_YOU_BIAN = 14;// 邮编
	private static final int INPUT_ADDRESS = 15;// 详细地址

	private static final String REQUEST_MODIFY_INFO = "request_modify_info";
	private static final String REQUEST_SAVE_IMAGE = "request_save_image";
	private static final String REQUEST_KE_SHI = "request_ke_shi";

	private WheelView mWheelProvince, mWheelCity, mWheelQu;
	private int mProvinceValue, mCityValue, mDistrictValue;

	private String mCurrentName = "";
	private String mCurrentCustomFeel = "";// 个性签名
	private String mCurrentHeight = "";
	private String mCurrentGender = "";
	private String mCurrentBirthDate = "";
	private String mCurrentPhone = "";
	private String mCurrentHospitalID = "";// 就诊医院id
	private String mCurrentHospitalName = "";// 就诊医院=================完善资料使用
	private String mCurrentKeShiID = "";// 科室id
	private String mCurrentKeShiName = "";// 科室=======================完善资料使用
	private String mCurrentIllHistorySendTags = "";// 病史，疾病标签
	private String mCurrentIllHistoryContent = "";// ===================完善资料使用
	private String mCurrentOperationType = "";//手术类型
	private String mCurrentOperationTime = "";
	private String mCurrentAreaID = "";
	private String mCurrentAreaName = "";// =============================完善资料使用
	private String mCurrentYouBian = "";
	private String mCurrentAddress = "";

	private String mLoginInfoBirthdate = "";
	private ArrayList<LoginInfoIllnessTags> mCurrentIllHistoryArrayList = null;// =======完善资料使用

	private boolean mFirstEnter = false;

	@Override
	public void onCreate(Bundle savedInstanceState) {

		mNeedSwipeBack = false;
		super.onCreate(savedInstanceState);
		setContentView(R.layout.my_userinfo_activity);

		init();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

	/**
	 * 添加页面动画，需要重写这个方法，
	 */
	@Override
	public void onBackPressed() {

		// 完善信息，禁止用户点击返回
		if (!mFirstEnter) {
//			if (!checkIfModify()) {
//				finish(true);
//			}
			finish(true);
		}
	}

	@Override
	public void onTopbarLeftLayoutSelected() {

//		if (!checkIfModify()) {
//			finish(true);
//		}
		finish(true);
	}

	@Override
	public void onTopbarRightButtonSelected() {
		save();
	}

	/**
	 * 初始化方法
	 */
	private void init() {
		// topbar
		CustomTopBarNew topbar = (CustomTopBarNew) findViewById(R.id.topbar);
		topbar.setTopbarTitle("个人信息");
		topbar.setonTopbarNewLeftLayoutListener(this);
		topbar.setRightText("保存");
		topbar.setOnTopbarNewRightButtonListener(this);

		Bundle data = getIntent().getExtras();
		if (data != null && data.size() > 0) {
			mFirstEnter = data.getBoolean("first_enter", false);
		}

		if (mFirstEnter) {
			topbar.setTopbarLeftLayoutHide();
		}

		updateInfo();
	}

	private void updateInfo() {

		ImageView accountIconImageView = (ImageView) findViewById(R.id.accountIconImageView);

		LoginInfo loginInfo = null;
		if (LoginUtil.checkIsLogin()) {
			loginInfo = MyApplication.getInstance().getLoginInfo();

			// update head icon
			LoginUtil.getUserIcon(this, accountIconImageView, loginInfo.UserID,true);
		} else {
			loginInfo = MyApplication.getInstance().mTempLoginInfo;
			accountIconImageView
					.setImageResource(R.drawable.my_icon_head_nologin);
		}

		if(loginInfo == null)
		{
			return;
		}

		// update name
		if (!TextUtils.isEmpty(loginInfo.TrueName)) {
			TextView nameValueTextView = (TextView) findViewById(R.id.nameValueTextView);
			nameValueTextView.setText(loginInfo.TrueName);

			mCurrentName = loginInfo.TrueName;
		}

		// update CustomFeel 个性签名
		if (!TextUtils.isEmpty(loginInfo.Whatsup)) {
			TextView customFeelValueTextView = (TextView) findViewById(R.id.customFeelValueTextView);
			customFeelValueTextView.setText(loginInfo.Whatsup);

			mCurrentCustomFeel = loginInfo.Whatsup;
		}

		// update Height
		if (!TextUtils.isEmpty(loginInfo.Height)) {
			TextView heightValueTextView = (TextView) findViewById(R.id.heightValueTextView);
			heightValueTextView.setText(String
					.format("%s cm", loginInfo.Height));

			mCurrentHeight = loginInfo.Height;
		}

		// update Gender
		if (!TextUtils.isEmpty(loginInfo.Gender)) {
			int gender = UtilityBase.parseInt(loginInfo.Gender);
			String[] array = getResources().getStringArray(
					R.array.array_userinfo_sex);
			TextView sexValueTextView = (TextView) findViewById(R.id.sexValueTextView);

			if (gender > 0) {
				sexValueTextView.setText(array[gender - 1]);
			} else {
				sexValueTextView.setText("");
			}

			mCurrentGender = loginInfo.Gender;
		}

		// update birthday
		if (!TextUtils.isEmpty(loginInfo.BirthYear)) {

			StringBuffer sb = new StringBuffer();
			sb.append(loginInfo.BirthYear);
			sb.append("-");
			if (loginInfo.BirthMonth.length() == 1) {
				sb.append("0");
			}
			sb.append(loginInfo.BirthMonth);
			sb.append("-");
			if (loginInfo.BirthDay.length() == 1) {
				sb.append("0");
			}
			sb.append(loginInfo.BirthDay);

			mLoginInfoBirthdate = sb.toString();

			TextView birthdayValueTextView = (TextView) findViewById(R.id.birthdayValueTextView);
			birthdayValueTextView.setText(mLoginInfoBirthdate);

			mCurrentBirthDate = mLoginInfoBirthdate;
		}

		// update mobile
		if (!TextUtils.isEmpty(loginInfo.Phone)) {
			TextView mobilePhoneValueTextView = (TextView) findViewById(R.id.mobilePhoneValueTextView);
			mobilePhoneValueTextView.setText(loginInfo.Phone);

			mCurrentPhone = loginInfo.Phone;
		}

		// update hospital
		if (!TextUtils.isEmpty(loginInfo.HospitalName)) {
			TextView hospitalValueTextView = (TextView) findViewById(R.id.hospitalValueTextView);
			hospitalValueTextView.setText(loginInfo.HospitalName);

			mCurrentHospitalID = loginInfo.HospitalID;
			mCurrentHospitalName = loginInfo.HospitalName;
		}

		// update keshi
		if (!TextUtils.isEmpty(loginInfo.DepartmentName)) {
			TextView keShiValueTextView = (TextView) findViewById(R.id.keShiValueTextView);
			keShiValueTextView.setText(loginInfo.DepartmentName);

			mCurrentKeShiID = loginInfo.DepartmentID;
			mCurrentKeShiName = loginInfo.DepartmentName;
		}

		// update IllnessTags
		mCurrentIllHistoryContent = getIllHistoryTagsContent(loginInfo.IllnessTags);

		TextView illHistoryValueTextView = (TextView) findViewById(R.id.illHistoryValueTextView);
		if(TextUtils.isEmpty(mCurrentIllHistoryContent))
		{
			illHistoryValueTextView.setText("无");
		}else{
			illHistoryValueTextView.setText(mCurrentIllHistoryContent);
		}

		// update operation type
		if (!TextUtils.isEmpty(loginInfo.Instrument)) {
			TextView operationTypeValueTextView = (TextView) findViewById(R.id.operationTypeValueTextView);

			int Instrument = UtilityBase.parseInt(loginInfo.Instrument);
			String[] array = getResources().getStringArray(
					R.array.array_userinfo_operation_type_old);
			if(Instrument >= array.length)
			{
				Instrument = 0;
			}

			if(Instrument <= 0)
			{
				operationTypeValueTextView.setText("无");
			}else{
				operationTypeValueTextView.setText(array[Instrument-1]);
			}

			mCurrentOperationType = String.valueOf(Instrument);
		}

		// update operation time
		if (!TextUtils.isEmpty(loginInfo.SurgicalTime)) {
			TextView operationTimeValueTextView = (TextView) findViewById(R.id.operationTimeValueTextView);
			operationTimeValueTextView.setText(loginInfo.SurgicalTime);

			mCurrentOperationTime = loginInfo.SurgicalTime;
		}

		//手术类型选择了无时
		updateOperateTimeSelectEnable();

		// update area
		if (!TextUtils.isEmpty(loginInfo.AreaName)) {
			TextView areaValueTextView = (TextView) findViewById(R.id.areaValueTextView);
			areaValueTextView.setText(loginInfo.AreaName);

			mCurrentAreaID = loginInfo.AreaID;
			mCurrentAreaName = loginInfo.AreaName;
		}

		// update youbian
		if (!TextUtils.isEmpty(loginInfo.ZipCode)) {
			TextView youbianValueTextView = (TextView) findViewById(R.id.youbianValueTextView);
			youbianValueTextView.setText(loginInfo.ZipCode);

			mCurrentYouBian = loginInfo.ZipCode;
		}

		// update address
		if (!TextUtils.isEmpty(loginInfo.Address)) {
			TextView addressValueTextView = (TextView) findViewById(R.id.addressValueTextView);
			addressValueTextView.setText(loginInfo.Address);

			mCurrentAddress = loginInfo.Address;
		}
	}

	private void updateOperateTimeSelectEnable()
	{
		RelativeLayout operationTimeLayout = (RelativeLayout) findViewById(R.id.operationTimeLayout);
		TextView operationTimeValueTextView = (TextView) findViewById(R.id.operationTimeValueTextView);

		int operationType = UtilityBase.parseInt(mCurrentOperationType);
		if(operationType == 0)
		{
			operationTimeLayout.setEnabled(false);
			operationTimeValueTextView.setText("");
			operationTimeValueTextView.setHint("选填");
		}else{
			operationTimeLayout.setEnabled(true);
			operationTimeValueTextView.setText(mCurrentOperationTime);
			operationTimeValueTextView.setHint("必填");
		}
	}

	/**
	 * 设置就诊医院
	 * 
	 * @param item
	 */
	public void setHospital(BeanMyUserInfoHospital item) {
		TextView hospitalValueTextView = (TextView) findViewById(R.id.hospitalValueTextView);
		hospitalValueTextView.setText(item.InstitutionName);

		mCurrentHospitalID = item.InstitutionID;
		mCurrentHospitalName = item.InstitutionName;
	}

	/**
	 * 设置病史
	 */
	public void setIllHistory(ArrayList<LoginInfoIllnessTags> selectedList) {

		if (selectedList == null || selectedList.size() == 0) {
			mCurrentIllHistoryContent = "";
			mCurrentIllHistorySendTags = getIllHistoryTagsSend(selectedList);
			mCurrentIllHistoryArrayList = null;

			TextView illHistoryValueTextView = (TextView) findViewById(R.id.illHistoryValueTextView);
			illHistoryValueTextView.setText("无");
		} else {
			mCurrentIllHistoryArrayList = selectedList;
			mCurrentIllHistoryContent = getIllHistoryTagsContent(selectedList);
			mCurrentIllHistorySendTags = getIllHistoryTagsSend(selectedList);

			TextView illHistoryValueTextView = (TextView) findViewById(R.id.illHistoryValueTextView);
			illHistoryValueTextView.setText(mCurrentIllHistoryContent);
		}
	}

	/**
	 * 获取病史，疾病标签 内容
	 */
	private String getIllHistoryTagsContent(
			ArrayList<LoginInfoIllnessTags> IllnessTags) {
		String value = "";
		if (IllnessTags != null && IllnessTags.size() > 0) {
			StringBuffer sb = new StringBuffer();
			for (LoginInfoIllnessTags item : IllnessTags) {
				sb.append(item.TagTitle);
				sb.append(",");
			}
			sb.deleteCharAt(sb.length() - 1);
			value = sb.toString();
		}

		return value;
	}

	/**
	 * 获取病史，疾病标签 发送标签
	 */
	private String getIllHistoryTagsSend(ArrayList<LoginInfoIllnessTags> newTags) {
		StringBuffer value = new StringBuffer();

		ArrayList<LoginInfoIllnessTags> historyTags = MyApplication
				.getInstance().getLoginInfo().IllnessTags;
		if (historyTags != null && historyTags.size() > 0) {
			for (LoginInfoIllnessTags item : historyTags) {
				value.append(String.format("%d_%d",
						UtilityBase.parseInt(item.TagID), 0));
				value.append("|");
			}
		}

		if (newTags != null && newTags.size() > 0) {

			for (LoginInfoIllnessTags item : newTags) {
				value.append(String.format("%d_%d",
						UtilityBase.parseInt(item.TagID), 1));
				value.append("|");
			}
		}

		if(!TextUtils.isEmpty(value) && value.length() > 0){
			value = value.deleteCharAt(value.length() - 1);
		}

		return value.toString();
	}

	/**
	 * 检查是否修改了资料
	 */
	private boolean checkIfModify() {
		boolean flag = false;

		LoginInfo loginInfo = MyApplication.getInstance().getLoginInfo();

		if (!mCurrentName.equals(loginInfo.TrueName)
				|| !mCurrentCustomFeel.equals(loginInfo.Whatsup)
				|| !mCurrentHeight.equals(loginInfo.Height)
				|| !mCurrentGender.equals(loginInfo.Gender)
				|| !mCurrentBirthDate.equals(mLoginInfoBirthdate)
				|| !mCurrentPhone.equals(loginInfo.Phone)
				|| !mCurrentHospitalID.equals(loginInfo.HospitalID)
				|| !mCurrentKeShiID.equals(loginInfo.DepartmentID)
				|| !mCurrentIllHistoryContent
						.equals(getIllHistoryTagsContent(loginInfo.IllnessTags))
				|| !mCurrentOperationType.equals(loginInfo.Instrument)
				|| !mCurrentOperationTime.equals(loginInfo.SurgicalTime)
				|| !mCurrentAreaID.equals(loginInfo.AreaID)
				|| !mCurrentYouBian.equals(loginInfo.ZipCode)
				|| !mCurrentAddress.equals(loginInfo.Address)) {
			flag = true;
		}

		if (flag) {
			String message = "是否放弃本次修改？";
			MyDialog dialog = new MyDialog(this)
					.setMessage(message)
					.setNegativeButton(R.string.app_cancel,
							new View.OnClickListener() {

								@Override
								public void onClick(View v) {

								}
							})
					.setPositiveButton(R.string.app_ok,
							new View.OnClickListener() {

								@Override
								public void onClick(View v) {
									finish(true);
								}
							});

			dialog.create(null);
			dialog.showMyDialog();
		}

		return flag;
	}

	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		UploadMenuImage.getInstance(this).onActivityResult(new CallBack() {
			@Override
			public void callBackSuccess(Object obj) {
				super.callBackSuccess(obj);

				uploadHeadIcon((String) obj);
			}
		}, requestCode, resultCode, data);

	};

	private void jumpHeadIcon()
	{
		PermissionUtil.getInstance().request(this, new String[]{Manifest.permission.CAMERA,
						Manifest.permission.READ_EXTERNAL_STORAGE,
						Manifest.permission.WRITE_EXTERNAL_STORAGE,},
				new PermissionResultCallBack() {
					@Override
					public void onPermissionGranted() {
						//
						String temp = SdLocal.getTempPhotoPath(MyUserInfoActivity.this, "temp_camera_icon");
						UploadMenuImage.getInstance(MyUserInfoActivity.this).setFilePath(temp);
						UploadMenuImage.getInstance(MyUserInfoActivity.this).setIsCut(true);
						UploadMenuImage.getInstance(MyUserInfoActivity.this).setIsPhotoDouble(false);

						UploadMenuImage.getInstance(MyUserInfoActivity.this).showPopAddPhoto();
					}

					@Override
					public void onPermissionGranted(String... permissions) {
						if (permissions == null || permissions.length == 0) {
						}
					}

					@Override
					public void onPermissionDenied(String... permissions) {
						if (permissions != null) {

						}
					}

					@Override
					public void onRationalShow(String... permissions) {
						if (permissions != null) {
							UIHelper.showToast(MyUserInfoActivity.this, R.string.permission_tip);
							PermissionUtil.openSettingActivity(MyUserInfoActivity.this);
						}
					}
				});
	}

	public void viewClick(View view) {

		int rid = view.getId();
		switch (rid) {
		case R.id.headIconLayout:

			jumpHeadIcon();
			break;
		case R.id.nameLayout:

			showInputPop(INPUT_NAME, "姓名");
			break;
		case R.id.customFeelLayout:

			showInputPop(INPUT_CUSTOM_FEEL, "个性签名");
			break;
		case R.id.heightLayout:

			showInputPop(INPUT_HEIGHT, "身高(cm)");
			break;
		case R.id.sexLayout:

			showGender();
			break;
		case R.id.birthdayLayout:

			showBirthDateDialog();
			break;
		case R.id.mobilePhoneLayout:

			showInputPop(INPUT_MOBILE_PHONE, "联系电话");
			break;
		case R.id.hospitalLayout:

			Intent intentHospital = new Intent(this,
					MyUserInfoHospitalActivity.class);
			startActivity(intentHospital, true);
			break;
		case R.id.keShiLayout:

			// from net
			requestKeShi();
			break;
		case R.id.illHistroyLayout:

			Intent intentIllHistory = new Intent(this,
					MyUserInfoIllHistoryActivity.class);
			startActivity(intentIllHistory, true);
			break;
		case R.id.operationTypeLayout:

			showOperationType();
			break;
		case R.id.operationTimeLayout:

			showOperationTimeDialog();
			break;
		case R.id.areaLayout:

			selectAddress();
			break;
		case R.id.youbianLayout:

			showInputPop(INPUT_YOU_BIAN, "邮编");
			break;
		case R.id.addressLayout:

			showInputPop(INPUT_ADDRESS, "详细地址");
			break;

		default:
			break;
		}
	}

	// ============================================================================
	/**
	 * 输入
	 */
	@SuppressLint("InflateParams")
	private void showInputPop(final int type, String title) {
		View view = LayoutInflater.from(this).inflate(
				R.layout.my_userinfo_select_input, null);

		TextView titleTextView = (TextView) view
				.findViewById(R.id.titleTextView);
		final EditText contentEditText = (EditText) view
				.findViewById(R.id.contentEditText);
		Button cancelButton = (Button) view.findViewById(R.id.cancelButton);
		Button okButton = (Button) view.findViewById(R.id.okButton);

		cancelButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				dismissInputPop();
			}
		});
		okButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				String content = contentEditText.getText().toString().trim();
				dowithInputUi(type, content);
			}
		});

		titleTextView.setText(title);

		LoginInfo loginInfo = MyApplication.getInstance().getLoginInfo();
		switch (type) {
		case INPUT_NAME:
			// 姓名
			if (TextUtils.isEmpty(mCurrentName)) {
				contentEditText.setText(loginInfo.TrueName);
			} else {
				contentEditText.setText(mCurrentName);
			}

			contentEditText.setInputType(InputType.TYPE_CLASS_TEXT);
			contentEditText.setFilters(new InputFilter[] { new EmojiFilter(),
					new InputFilter.LengthFilter(10) });// 10
			break;
		case INPUT_CUSTOM_FEEL:
			// 个性签名
			if (TextUtils.isEmpty(mCurrentCustomFeel)) {
				contentEditText.setText(loginInfo.Whatsup);
			} else {
				contentEditText.setText(mCurrentCustomFeel);
			}
			contentEditText.setFilters(new InputFilter[] { new EmojiFilter(),
					new InputFilter.LengthFilter(50) });// 50
			break;
		case INPUT_HEIGHT:
			// 身高
			if (TextUtils.isEmpty(mCurrentHeight)) {
				contentEditText.setText(loginInfo.Height);
			} else {
				contentEditText.setText(mCurrentHeight);
			}

			contentEditText.setInputType(InputType.TYPE_CLASS_NUMBER);
			contentEditText.setFilters(new InputFilter[] { new EmojiFilter(),
					new InputFilter.LengthFilter(3) });// 3
			break;
		case INPUT_MOBILE_PHONE:
			// 联系电话
			if (TextUtils.isEmpty(mCurrentPhone)) {
				contentEditText.setText(loginInfo.MobilePhone);
			} else {
				contentEditText.setText(mCurrentPhone);
			}

			contentEditText.setInputType(InputType.TYPE_CLASS_NUMBER);
			contentEditText.setFilters(new InputFilter[] { new EmojiFilter(),
					new InputFilter.LengthFilter(11) });// 11
			break;
		case INPUT_YOU_BIAN:
			// 邮编
			if (TextUtils.isEmpty(mCurrentYouBian)) {
				contentEditText.setText(loginInfo.ZipCode);
			} else {
				contentEditText.setText(mCurrentYouBian);
			}

			contentEditText.setInputType(InputType.TYPE_CLASS_NUMBER);
			contentEditText.setFilters(new InputFilter[] { new EmojiFilter(),
					new InputFilter.LengthFilter(6) });// 6
			break;
		case INPUT_ADDRESS:
			// 详细地址
			if (TextUtils.isEmpty(mCurrentAddress)) {
				contentEditText.setText(loginInfo.Address);
			} else {
				contentEditText.setText(mCurrentAddress);
			}

			contentEditText.setFilters(new InputFilter[] { new EmojiFilter(),
					new InputFilter.LengthFilter(50) });// 50
			break;

		default:
			break;
		}

		PopUtil.getInstance().showPopWindow(this, null, view, Gravity.BOTTOM,
				null, false);
	}

	private void dismissInputPop() {

		PopUtil.getInstance().dismissPopWindow();
	}

	/**
	 * 处理输入ui
	 */
	private void dowithInputUi(int type, String content) {

		switch (type) {
		case INPUT_NAME:

			if (content.length() < 2) {
				UIHelper.showToast(this, R.string.my_userinfo_name_tip);
				return;
			}

			TextView nameValueTextView = (TextView) findViewById(R.id.nameValueTextView);
			nameValueTextView.setText(content);

			mCurrentName = content;
			break;
		case INPUT_CUSTOM_FEEL:

			// 选填
			TextView customFeelValueTextView = (TextView) findViewById(R.id.customFeelValueTextView);
			customFeelValueTextView.setText(content);

			mCurrentCustomFeel = content;
			break;
		case INPUT_HEIGHT:

			// 选填
			TextView heightValueTextView = (TextView) findViewById(R.id.heightValueTextView);
			if (content.length() > 0) {
				int height = UtilityBase.parseInt(content);
				if (height < 110 || height > 220) {
					UIHelper.showToast(this, R.string.my_userinfo_height_tip);
					return;
				}

				heightValueTextView.setText(String.format("%s cm", content));
			}else{
				heightValueTextView.setText(String.format("%s", content));
			}
			mCurrentHeight = content;
			break;
		case INPUT_MOBILE_PHONE:

			if (content.length() != 11) {
				UIHelper.showToast(this, R.string.my_userinfo_phone_tip);
				return;
			}

			TextView mobilePhoneValueTextView = (TextView) findViewById(R.id.mobilePhoneValueTextView);
			mobilePhoneValueTextView.setText(content);

			mCurrentPhone = content;
			break;
		case INPUT_YOU_BIAN:

			// 选填
			if (content.length() > 0) {
				if (content.length() != 6) {
					UIHelper.showToast(this, R.string.my_userinfo_zipcode_tip);
					return;
				}
			}
			
			TextView youbianValueTextView = (TextView) findViewById(R.id.youbianValueTextView);
			youbianValueTextView.setText(content);

			mCurrentYouBian = content;

			break;
		case INPUT_ADDRESS:

			if (TextUtils.isEmpty(content)) {
				UIHelper.showToast(this, R.string.my_userinfo_address_tip);
				return;
			}

			TextView addressValueTextView = (TextView) findViewById(R.id.addressValueTextView);
			addressValueTextView.setText(content);

			mCurrentAddress = content;
			break;

		default:
			break;
		}

		dismissInputPop();
	}

	// =========================================================================================================

	/**
	 * 选择性别
	 */
	private void showGender() {
		final String[] array = getResources().getStringArray(
				R.array.array_userinfo_sex);
		new MyDialog(this)
				.setSimpleItems(array, new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {

						mCurrentGender = String.valueOf(which + 1);

						String value = array[which];

						TextView sexValueTextView = (TextView) findViewById(R.id.sexValueTextView);
						sexValueTextView.setText(value);
					}
				}).create(null).show();

	}

	/**
	 * 选择手术类型
	 */
	private void showOperationType() {
		final String[] array = getResources().getStringArray(
				R.array.array_userinfo_operation_type);
		final String[] arrayValue = getResources().getStringArray(
				R.array.array_userinfo_operation_type_value);

		new MyDialog(this)
				.setSimpleItems(array, new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {

						mCurrentOperationType = arrayValue[which];

						updateOperateTimeSelectEnable();

						String value = array[which];

						TextView operationTypeValueTextView = (TextView) findViewById(R.id.operationTypeValueTextView);
						operationTypeValueTextView.setText(value);
						
						//=====
						TextView operationTimeValueTextView = (TextView) findViewById(R.id.operationTimeValueTextView);
						if(value.equals("无"))
						{
							operationTimeValueTextView.setHint("选填");
							operationTimeValueTextView.setText("");
						}else{
							operationTimeValueTextView.setHint("必填");
						}
					}
				}).create(null).show();

	}

	/**
	 * 选择科室
	 */
	private void showKeShi(final ArrayList<BeanMyUserInfoKeShi> dataArraylist) {

		if (dataArraylist != null && dataArraylist.size() > 0) {
			final String[] array = new String[dataArraylist.size()];
			int currentIndex = 0;

			for (int i = 0; i < dataArraylist.size(); i++) {
				array[i] = dataArraylist.get(i).InstitutionName;
				if (mCurrentKeShiID.equals(dataArraylist.get(i).InstitutionID)) {
					currentIndex = i;
				}
			}

			final MyDialog dialog = new MyDialog(this);
			dialog.setSimpleSelectPicker(array, currentIndex)
					.setTitle("科室")
					.setNegativeButton(R.string.app_cancel,
							new View.OnClickListener() {

								@Override
								public void onClick(View v) {

								}
							})
					.setPositiveButton(R.string.app_ok,
							new View.OnClickListener() {

								@Override
								public void onClick(View v) {

									WheelView wv_content = (WheelView) v
											.findViewById(R.id.simpleSelectPicker);
									int index = wv_content.getCurrentItem();

									TextView keShiValueTextView = (TextView) findViewById(R.id.keShiValueTextView);
									keShiValueTextView.setText(array[index]);

									mCurrentKeShiID = dataArraylist.get(index).InstitutionID;
									mCurrentKeShiName = dataArraylist
											.get(index).InstitutionName;

								}
							}).create(null).show();
		} else {
			UIHelper.showToast(this, "暂时没有科室");
		}
	}

	/**
	 * 选择出生年月日
	 */
	private void showBirthDateDialog() {

		String dateStr = "";
		if (TextUtils.isEmpty(mCurrentBirthDate)) {
			dateStr = DateUtilBase.stringFromDate(new Date(),
					DateUtilBase.YEAR_MONTH_DAY);
		} else {
			dateStr = mCurrentBirthDate;
		}

		Date date = DateUtilBase.dateFromString(dateStr,
				DateUtilBase.YEAR_MONTH_DAY);
		MyDialog dialog = new MyDialog(this)
				.setTitle("出生日期")
				.setDateTimePicker(date, DateType.YEAR_MONTH_DAY)
				.setNegativeButton(R.string.app_cancel,
						new View.OnClickListener() {

							@Override
							public void onClick(View arg0) {

							}
						})
				.setPositiveButton(R.string.app_ok, new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// 如果是个数,则显示为"02"的样式
						WheelView wv_year = (WheelView) v
								.findViewById(R.id.year);
						WheelView wv_month = (WheelView) v
								.findViewById(R.id.month);
						WheelView wv_day = (WheelView) v.findViewById(R.id.day);

						String parten = "00";
						DecimalFormat decimal = new DecimalFormat(parten);
						// 设置日期的显示
						String text = (wv_year.getCurrentItem() + MyDialog.START_YEAR)
								+ "-"
								+ decimal.format((wv_month.getCurrentItem() + 1))
								+ "-"
								+ decimal.format((wv_day.getCurrentItem() + 1));

						Date selectDate = DateUtilBase.dateFromString(text,
								DateUtilBase.YEAR_MONTH_DAY);
						Date currentDate = new Date(System.currentTimeMillis());

						if (selectDate.after(currentDate)) {
							UIHelper.showToast(MyUserInfoActivity.this,
									"请选择正确的出生日期");
							return;
						}

						TextView birthdayValueTextView = (TextView) findViewById(R.id.birthdayValueTextView);
						birthdayValueTextView.setText(text);

						mCurrentBirthDate = text;
					}
				});

		dialog.create(null).show();
	}

	/**
	 * 选择手术时间
	 */
	private void showOperationTimeDialog() {

		String dateStr = "";
		if (TextUtils.isEmpty(mCurrentOperationTime)) {
			dateStr = DateUtilBase.stringFromDate(new Date(),
					DateUtilBase.YEAR_MONTH_DAY);
		} else {
			dateStr = mCurrentOperationTime;
		}

		Date date = DateUtilBase.dateFromString(dateStr,
				DateUtilBase.YEAR_MONTH_DAY);

		MyDialog dialog = new MyDialog(this)
				.setTitle("手术时间")
				.setDateTimePicker(date, DateType.YEAR_MONTH_DAY)
				.setNegativeButton(R.string.app_cancel,
						new View.OnClickListener() {

							@Override
							public void onClick(View arg0) {

							}
						})
				.setPositiveButton(R.string.app_ok, new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// 如果是个数,则显示为"02"的样式
						WheelView wv_year = (WheelView) v
								.findViewById(R.id.year);
						WheelView wv_month = (WheelView) v
								.findViewById(R.id.month);
						WheelView wv_day = (WheelView) v.findViewById(R.id.day);

						String parten = "00";
						DecimalFormat decimal = new DecimalFormat(parten);
						// 设置日期的显示
						String text = (wv_year.getCurrentItem() + MyDialog.START_YEAR)
								+ "-"
								+ decimal.format((wv_month.getCurrentItem() + 1))
								+ "-"
								+ decimal.format((wv_day.getCurrentItem() + 1));

						Date selectDate = DateUtilBase.dateFromString(text,
								DateUtilBase.YEAR_MONTH_DAY);
						Date currentDate = new Date(System.currentTimeMillis());

						if (selectDate.after(currentDate)) {
							UIHelper.showToast(MyUserInfoActivity.this,
									"请选择正确的手术时间");
							return;
						}

						TextView operationTimeValueTextView = (TextView) findViewById(R.id.operationTimeValueTextView);
						operationTimeValueTextView.setText(text);

						mCurrentOperationTime = text;
					}
				});

		dialog.create(null).show();
	}

	private void getAreaInfo() {
		int provincePosition = mProvinceValue;
		int cityPosition = mCityValue;
		int districtPosition = mDistrictValue;

		BeanArea province;
		BeanArea city;
		BeanArea district;

		ArrayList<BeanArea> provinceList = BeanArea.getAreaByExtra("0");// 0,1,2
		String shiExtra = "0" + "," + provinceList.get(provincePosition).Id;
		ArrayList<BeanArea> shiList = BeanArea.getAreaByExtra(shiExtra);

		String areaName = "";
		province = provinceList.get(provincePosition);
		if (shiList != null && shiList.size() != 0) {
			city = shiList.get(cityPosition);
			mCurrentAreaID = String.valueOf(city.Id);
			areaName = province.Name + "  " + city.Name;

			String quExtra = shiExtra + "," + shiList.get(cityPosition).Id;
			ArrayList<BeanArea> quList = BeanArea.getAreaByExtra(quExtra);

			if (quList != null && quList.size() != 0) {
				district = quList.get(districtPosition);
				mCurrentAreaID = String.valueOf(district.Id);
				areaName = province.Name + "  " + city.Name + "  "
						+ district.Name;
			}
		}

		mCurrentAreaName = areaName;
		TextView areaValueTextView = (TextView) findViewById(R.id.areaValueTextView);
		areaValueTextView.setText(areaName);
	}

	@SuppressLint("InflateParams")
	private void selectAddress() {

		final ArrayList<BeanArea> provinceList = BeanArea.getAreaByExtra("0");// 0,1,2
		String shiExtra = "0" + "," + provinceList.get(mProvinceValue).Id;
		ArrayList<BeanArea> shiList = BeanArea.getAreaByExtra(shiExtra);
		String quExtra = shiExtra + "," + shiList.get(mCityValue).Id;
		ArrayList<BeanArea> quList = BeanArea.getAreaByExtra(quExtra);

		final MyDialog myDialog = new MyDialog(this);
		View view = getLayoutInflater().inflate(
				R.layout.app_province_city_qu_dialog, null);

		mWheelProvince = (WheelView) view.findViewById(R.id.province);
		mWheelCity = (WheelView) view.findViewById(R.id.city);
		mWheelQu = (WheelView) view.findViewById(R.id.qu);

		// 根据屏幕密度来指定选择器字体的大小
		int textSize = UtilityBase.getTextNumberSize(this);

		mWheelProvince.TEXT_SIZE = textSize;
		mWheelCity.TEXT_SIZE = textSize;
		mWheelQu.TEXT_SIZE = textSize;

		// 省
		mWheelProvince.setAdapter(new ProvinceWheelAdapter(provinceList));// 设置"年"的显示数据
		mWheelProvince.setCyclic(false);// 可循环滚动
		mWheelProvince.setCurrentItem(mProvinceValue);// 初始化时显示的数据

		// 市
		mWheelCity.setAdapter(new CityWheelAdapter(shiList));
		mWheelCity.setCyclic(false);
		mWheelCity.setCurrentItem(mCityValue);

		// 区
		mWheelQu.setCyclic(false);
		mWheelQu.setAdapter(new DistrictWheelAdapter(quList));
		mWheelQu.setCurrentItem(mDistrictValue);

		OnWheelChangedListener provinceListner = new OnWheelChangedListener() {

			@Override
			public void onChanged(WheelView wheel, int oldValue, int newValue) {
				mProvinceValue = newValue;

				String shiExtraTemp = "0" + ","
						+ provinceList.get(mProvinceValue).Id;
				ArrayList<BeanArea> shiListTemp = BeanArea
						.getAreaByExtra(shiExtraTemp);

				if (shiListTemp != null && shiListTemp.size() != 0) {
					mWheelCity.setAdapter(new CityWheelAdapter(shiListTemp));
					mWheelCity.setCurrentItem(0);

					String quExtra = shiExtraTemp + "," + shiListTemp.get(0).Id;
					ArrayList<BeanArea> quListTemp = BeanArea
							.getAreaByExtra(quExtra);

					Log.i("hz", "has city");
					if (quListTemp != null && quListTemp.size() != 0) {
						mWheelQu.setAdapter(new DistrictWheelAdapter(quListTemp));
						mWheelQu.setCurrentItem(0);
					} else {
						ArrayList<BeanArea> array = new ArrayList<BeanArea>();
						BeanArea district = new BeanArea();
						district.Name = shiListTemp.get(0).Name;
						array.add(district);
						mWheelQu.setAdapter(new DistrictWheelAdapter(array));
						mWheelQu.setCurrentItem(0);
					}

				} else {
					Log.i("hz", "no city");
					ArrayList<BeanArea> array = new ArrayList<BeanArea>();
					BeanArea city = new BeanArea();
					city.Name = provinceList.get(newValue).Name;
					array.add(city);

					mWheelQu.setAdapter(new CityWheelAdapter(array));
					mWheelQu.setCurrentItem(0);
					ArrayList<BeanArea> disArray = new ArrayList<BeanArea>();
					BeanArea district = new BeanArea();
					district.Name = provinceList.get(newValue).Name;
					disArray.add(district);
					mWheelQu.setAdapter(new DistrictWheelAdapter(disArray));
					mWheelQu.setCurrentItem(0);
				}

			}
		};

		OnWheelChangedListener cityListner = new OnWheelChangedListener() {

			@Override
			public void onChanged(WheelView wheel, int oldValue, int newValue) {
				mCityValue = newValue;

				String shiExtraTemp = "0" + ","
						+ provinceList.get(mProvinceValue).Id;
				ArrayList<BeanArea> shiListTemp = BeanArea
						.getAreaByExtra(shiExtraTemp);

				String quExtraTemp = shiExtraTemp + ","
						+ shiListTemp.get(newValue).Id;
				ArrayList<BeanArea> quListTemp = BeanArea
						.getAreaByExtra(quExtraTemp);

				if (quListTemp != null && quListTemp.size() != 0) {
					mWheelQu.setAdapter(new DistrictWheelAdapter(quListTemp));
					mWheelQu.setCurrentItem(0);
					Log.i("hz", "has district");
				} else {
					Log.i("hz", "no district");
					ArrayList<BeanArea> array = new ArrayList<BeanArea>();
					BeanArea district = new BeanArea();
					district.Name = shiListTemp.get(newValue).Name;
					array.add(district);
					mWheelQu.setAdapter(new DistrictWheelAdapter(array));
					mWheelQu.setCurrentItem(0);
				}
			}
		};

		OnWheelChangedListener districtListner = new OnWheelChangedListener() {
			@Override
			public void onChanged(WheelView wheel, int oldValue, int newValue) {
				mDistrictValue = newValue;
			}
		};

		mWheelProvince.addChangingListener(provinceListner);
		mWheelCity.addChangingListener(cityListner);
		mWheelQu.addChangingListener(districtListner);

		TextView okTextView = (TextView) view.findViewById(R.id.okTextView);
		okTextView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				myDialog.dismiss();
				getAreaInfo();
			}
		});

		myDialog.addView(view);
		myDialog.create(null);
		myDialog.showMyDialog();
	}

	private void uploadHeadIcon(String filePath) {
		if (!TextUtils.isEmpty(filePath)) {
			File userFile = new File(filePath);
			if (!userFile.exists()) {
				UIHelper.showToast(this, "上传头像失败，请重试");
				return;
			}
			try {
				String UserID = "";
				String LoginToken = "";

				if (LoginUtil.checkIsLogin()) {
					UserID = LoginUtil.getUserId();
					LoginToken = LoginUtil.getLoginToken();
				} else {
					UserID = MyApplication.getInstance().mTempLoginInfo.UserID;
					LoginToken = MyApplication.getInstance().mTempLoginInfo.LoginToken;
				}
				// String tempPath = SdLocal.getTempPhotoPath(this);
				// ImageCompressUtils.CompressImageFile(filePath, tempPath);

				Map<String, File> fileMaps = new HashMap<String, File>();
				fileMaps.put("Avatar", new File(filePath));

				Map<String, Object> map = new HashMap<String, Object>();
				try {
					JSONObject params = new JSONObject();
					params.put("DeviceID", Setting.DEVICEID);
					params.put("ApplicationID", Setting.APPLICATIONID);

					params.put("UserID", UserID);
					params.put("LoginToken", LoginToken);

					map.put("ht", params);
				} catch (Exception e) {
					e.printStackTrace();
				}

				showProgressDialog(false);
				ApiClient.http_post_main(Setting.getUserHeadIconUrl(), map,
						fileMaps, this, REQUEST_SAVE_IMAGE, true);

			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	private void save() {

		// 选填 个性签名
		if (mCurrentCustomFeel.length() > 50) {
			UIHelper.showToast(this, R.string.my_userinfo_CustomFeel_tip);
			return;
		}

		// name
		if (mCurrentName.length() < 2) {
			UIHelper.showToast(this, R.string.my_userinfo_name_tip);
			return;
		}

		// sex
		if (TextUtils.isEmpty(mCurrentGender)) {
			UIHelper.showToast(this, "请选择性别");
			return;
		}

		// birthday
		if (TextUtils.isEmpty(mCurrentBirthDate)) {
			UIHelper.showToast(this, "请选择出生日期");
			return;
		}

		// 选填 身高
		if (mCurrentHeight.length() > 0) {
			int height = UtilityBase.parseInt(mCurrentHeight);
			if (height < 110 || height > 220) {
				UIHelper.showToast(this, R.string.my_userinfo_height_tip);
				return;
			}
		}

		// 联系方式
		if (mCurrentPhone.length() != 11) {
			UIHelper.showToast(this, R.string.my_userinfo_phone_tip);
			return;
		}

		// 就诊医院
		if (TextUtils.isEmpty(mCurrentHospitalID)) {
			UIHelper.showToast(this, "请选择就诊医院");
			return;
		}

		// 科室
		if (TextUtils.isEmpty(mCurrentKeShiID)) {
			UIHelper.showToast(this, "请选择科室");
			return;
		}

		// 病史
		TextView illHistoryValueTextView = (TextView) findViewById(R.id.illHistoryValueTextView);
		String tempIllHistory = illHistoryValueTextView.getText().toString();
		if (TextUtils.isEmpty(mCurrentIllHistoryContent) && !tempIllHistory.equals("无")) {
			UIHelper.showToast(this, "请选择病史");
			return;
		}

		// 手术类型
		if (TextUtils.isEmpty(mCurrentOperationType)) {
			UIHelper.showToast(this, "请选择手术类型");
			return;
		}

		// 手术时间
		//手术类型选择了无，手术时间选填。
		int operationType = UtilityBase.parseInt(mCurrentOperationType);
		if(operationType != 0)
		{
			//手术类型没有选择了无
			if (TextUtils.isEmpty(mCurrentOperationTime)) {
				UIHelper.showToast(this, "请选择手术时间");
				return;
			}
		}

		// 所在地区
		if (TextUtils.isEmpty(mCurrentAreaID)) {
			UIHelper.showToast(this, "请选择所在地区");
			return;
		}

		// 选填 邮编
		if (mCurrentYouBian.length() > 0) {
			if (mCurrentYouBian.length() != 6) {
				UIHelper.showToast(this, R.string.my_userinfo_zipcode_tip);
				return;
			}
		}

		// 详细地址
		if (TextUtils.isEmpty(mCurrentAddress)) {
			UIHelper.showToast(this, R.string.my_userinfo_address_tip);
			return;
		}

		Date date = DateUtilBase.dateFromString(mCurrentBirthDate, "yyyy-M-d");
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);

		int birthYear = calendar.get(Calendar.YEAR);
		int birthMonth = calendar.get(Calendar.MONTH) + 1;
		int birthDay = calendar.get(Calendar.DATE);

		String UserID = "";
		String LoginToken = "";

		if (LoginUtil.checkIsLogin()) {
			UserID = LoginUtil.getUserId();
			LoginToken = LoginUtil.getLoginToken();
		} else {
			if(MyApplication.getInstance().mTempLoginInfo != null)
			{
				UserID = MyApplication.getInstance().mTempLoginInfo.UserID;
				LoginToken = MyApplication.getInstance().mTempLoginInfo.LoginToken;
			}
		}

		String url = Setting.getMyUserInfoSaveUrl();

		Map<String, Object> map = new HashMap<String, Object>();
		JSONObject params = new JSONObject();
		try {
			params.put("DeviceID", Setting.DEVICEID);
			params.put("ApplicationID", Setting.APPLICATIONID);

			params.put("UserID", UserID);
			params.put("LoginToken", LoginToken);

			params.put("TrueName", mCurrentName);
			params.put("Gender", mCurrentGender);
			params.put("BirthYear", birthYear);
			params.put("BirthMonth", birthMonth);
			params.put("BirthDay", birthDay);
			params.put("Phone", mCurrentPhone);
			params.put("HospitalID", mCurrentHospitalID);
			params.put("DepartmentID", mCurrentKeShiID);
			params.put("IllnessTags", mCurrentIllHistorySendTags);
			params.put("Instrument", mCurrentOperationType);//手术类型
			params.put("SurgicalTime", mCurrentOperationTime);
			params.put("AreaID", mCurrentAreaID);
			params.put("Address", mCurrentAddress);
			params.put("Height", mCurrentHeight);

			// new add
			params.put("Whatsup", mCurrentCustomFeel);// 个性签名
			params.put("ZipCode", mCurrentYouBian);// 邮编

		} catch (Exception e) {
		}
		map.put("ht", params);

		showProgressDialog(false);
		ApiClient.http_post_main(url, map, null, this, REQUEST_MODIFY_INFO,
				true);
	}

	private void requestKeShi() {

		if (TextUtils.isEmpty(mCurrentHospitalID)) {
			UIHelper.showToast(this, "请先选择就诊医院");
			return;
		}

		String url = Setting.getMyUserInfoKeShiUrl();

		Map<String, Object> map = new HashMap<String, Object>();
		JSONObject params = new JSONObject();
		try {
			params.put("DeviceID", Setting.DEVICEID);
			params.put("ApplicationID", Setting.APPLICATIONID);

			params.put("ParentInstitutionID", mCurrentHospitalID);
			params.put("InstitutionTypeList", "6");

		} catch (Exception e) {
		}
		map.put("ht", params);

		showProgressDialog(false);
		ApiClient.http_post_main(url, map, null, this, REQUEST_KE_SHI, true,
				false, true);
	}

	private LoginInfo getCustomLoginInfo() {
		Date date = DateUtilBase.dateFromString(mCurrentBirthDate, "yyyy-M-d");
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);

		int birthYear = calendar.get(Calendar.YEAR);
		int birthMonth = calendar.get(Calendar.MONTH) + 1;
		int birthDay = calendar.get(Calendar.DATE);

		String UserID = "";
		String LoginToken = "";
		String NickName = "";

		String MobilePhone = "";//手机号
		String HasSecurityQuestion="";

		if (LoginUtil.checkIsLogin()) {
			UserID = LoginUtil.getUserId();
			LoginToken = LoginUtil.getLoginToken();
			NickName = MyApplication.getInstance().getLoginInfo().NickName;

			MobilePhone = MyApplication.getInstance().getLoginInfo().MobilePhone;
			HasSecurityQuestion = MyApplication.getInstance().getLoginInfo().HasSecurityQuestion;
		} else {
			UserID = MyApplication.getInstance().mTempLoginInfo.UserID;
			LoginToken = MyApplication.getInstance().mTempLoginInfo.LoginToken;
			NickName = MyApplication.getInstance().mTempLoginInfo.NickName;

			MobilePhone = MyApplication.getInstance().mTempLoginInfo.MobilePhone;
			HasSecurityQuestion = MyApplication.getInstance().mTempLoginInfo.HasSecurityQuestion;
		}

		LoginInfo info = new LoginInfo();

		info.MobilePhone = MobilePhone;
		info.HasSecurityQuestion = HasSecurityQuestion;

		info.UserID = UserID;
		info.LoginToken = LoginToken;
		info.TrueName = mCurrentName;
		info.Gender = mCurrentGender;
		info.BirthYear = birthYear + "";
		info.BirthMonth = birthMonth + "";
		info.BirthDay = birthDay + "";
		info.Phone = mCurrentPhone;
		info.HospitalID = mCurrentHospitalID;
		info.HospitalName = mCurrentHospitalName;
		info.DepartmentID = mCurrentKeShiID;
		info.DepartmentName = mCurrentKeShiName;
		info.IllnessTags = mCurrentIllHistoryArrayList;
		info.Instrument = mCurrentOperationType;  //手术类型
		info.SurgicalTime = mCurrentOperationTime;
		info.AreaID = mCurrentAreaID;
		info.AreaName = mCurrentAreaName;
		info.Address = mCurrentAddress;
		info.Height = mCurrentHeight;

		info.NickName = NickName;

		// new add
		info.Whatsup = mCurrentCustomFeel;// 个性签名
		info.ZipCode = mCurrentYouBian;// 邮编

		return info;
	}

	@Override
	public void RequestComplete(Object object, Object data) {
		if (object.equals(REQUEST_MODIFY_INFO)) {
			hideProgressDialog();

			LoginInfo.saveLoginInfo(this, getCustomLoginInfo());

			if (mFirstEnter) {
				// 注册成功，完善资料后，当作成功，进行更新
				ObserverManager.getInstance().notify(
						ObserverConst.NOTIFY_MY_LOGIN_STATE_CHANGE, null,
						LoginInfo.TYPE_LOGIN);
			}

			// 完善资料成功，
			mFirstEnter = false;
			finish(true);

			LoginUtil.jumpMainActivity(this);
		} else if (object.equals(REQUEST_SAVE_IMAGE)) {
			hideProgressDialog();

			// 删除旧头像，重新下载新的头像
			String UserID = "";
			if (LoginUtil.checkIsLogin()) {
				UserID = LoginUtil.getUserId();
			} else {
				UserID = MyApplication.getInstance().mTempLoginInfo.UserID;
			}

			String userPath = SdLocal.getUserPath(this, UserID);
			File userFile = new File(userPath);
			if(userFile.exists())
			{
				userFile.delete();
			}

			BitmapManager.clearBitmapMemoryCache();
			// tempPath
			String tempath = SdUtilBase.getTempIconPath(this);
			Bitmap bitmap = ImageUtilBase.getBitmap(tempath);
			ImageUtilBase.saveImageToSd(bitmap,
					userPath);

			ImageView accountIconImageView = (ImageView) findViewById(R.id.accountIconImageView);
			if(bitmap != null)
			{
				accountIconImageView.setImageBitmap(bitmap);
			}
		} else if (object.equals(REQUEST_KE_SHI)) {
			hideProgressDialog();

			// 解析json data
			ArrayList<BeanMyUserInfoKeShi> dataArraylist = BeanMyUserInfoKeShi
					.parseJsonData((String) data);
			showKeShi(dataArraylist);
		}
	}

	@Override
	public void RequestError(Object object, int errorId, String errorMessage) {
		if (object.equals(REQUEST_MODIFY_INFO)) {
			hideProgressDialog();
		} else if (object.equals(REQUEST_SAVE_IMAGE)) {
			hideProgressDialog();
		} else if (object.equals(REQUEST_KE_SHI)) {
			hideProgressDialog();
		}
	}

}
